window.undefined = window.undefined;
var href_path = window.location.href;
href_path = href_path.substring(0,href_path.indexOf("/pages/headmap"));

var Terren = {
	version: '3.7',
	path: href_path + '/webview/headMap_' // 服务地址
}

Terren.Config = {
	zIndex: 10000,
	opacity: 60,
	selectList: [],
	split: "***",
	separator: "@@@",
	color: {
		blue: '#336699',
		green: '#44975F',
		red: '#CC0000',
		orange: '#FF7400',
		white: '#ffffff',
		black: '#000000'
	},
	render: {
		color1: '#FF3333',
		color2: '#FFFF33',
		color3: '#FF9933',
		color4: '#3399FF',
		color5: '#99FF33',
		color6: '#66FFFF',
		color7: '#CCCCCC'
	}
}

Terren.element = {}

// 初始化配置
Terren.element.config = function(config) {
	this.config = {
		type: 1
	}
	this.defaultList = [];
	this.initConfig(config);
}
Terren.element.config.prototype = {
	initConfig: function(config) {
		if(config) {
			for(var i in config) {
				eval("this.config." + i + "=config." + i);
			}
		}
	},
	script_ajax: function(params) {
		var config = {
			url: Terren.path,
			params: "getBlockInfo?callback=json"+params,
			callBack: this.script_proxy,
			element: this
		}
		new Terren.element.script_proxy(config);
	},
	script_ajax2: function(params) {
		var config = {
			url: Terren.path,
			params: "getBlockInfoByDate?callback=json"+params,
			callBack: this.script_proxy,
			element: this
		}
		new Terren.element.script_proxy(config);
	},
	script_proxy: function() {
		this.element.script_callback();
	},
	script_callback: function() {
		var items = json.items;
		for(var i=0;i<items.length;i++) {
			var blockQuery = items[i].blockQuery;
			if(!blockQuery) {
				continue;
			}
			blockQuery = blockQuery.replace("]","");
			var blockArray = blockQuery.split("[");
			if(blockArray.length != 2) {
				continue;
			}
			var object = {};
			object.nodeName = blockArray[0];
			var queryArray = blockArray[1].split("=");
			object.attribute = queryArray[0];
			object.value = queryArray[1];
			object.name = items[i].name;
			object.pv = items[i].pv;
			object.totalpv = items[i].totalpv;
			this.defaultList.push(object);
		}
		this.init_block();
	},
	init_block: function() {
		var type = this.config.type;
		for(var i=0;i<this.defaultList.length;i++) {
				var block = this.defaultList[i];
				var object;
				if(block.attribute == "id") {
					object = document.getElementById(block.value);
				} else {
					object = Terren.util.getElementByAttribute(block);
				}
				if(!object) {
					continue;
				}
				
				object.block = block;
				object.blocktype = type;
				
				if(object.style.display == "none") {
					Terren.Config.selectList.push(object);
					continue;
				}
				
				var panel = Terren.util.createPanel(object);
	    		object.panel = panel;
	    		
	    		var panel_filter =  Terren.util.createFilterPanel(object);
	    		object.panel_filter = panel_filter;
	    		
	    		Terren.Config.selectList.push(object);
		}
		Terren.util.ondisplay();
	}
}

/**
 * 面板
 * @param {} config
 */
Terren.element.Panel = function(config) {
	this.config = { // 面板参数
		id: 'terren',
		fontFamily: '宋体',
		position: 'absolute',
		background: Terren.Config.color.black,
		top: 0 + "px",
		left: 0 + "px"
	}
	this.initConfig(config); // 初始化面板参数
	this.element; // 面板元素
	this.state = 1; // 1未选择 2已选择 3新选择
	this.init(); // 初始化面板
}
Terren.element.Panel.prototype = {
	initConfig: function(config) {
		if(config && config.transparence) {
			config.opacity = '.' + Terren.Config.opacity;
			config.filter = 'alpha(opacity=' + Terren.Config.opacity + ')';
		}
		for(var i in config) { // 自定义参数赋值
			eval("this.config." + i + "=config." + i);
		}	
	},
	init: function() {
		var div = document.createElement("div");
    	for(var i in this.config) {
    		// div.style.setAttribute(i, this.config[i]);
    		eval("div.style." + i + "='" + this.config[i] + "'");
		}
		div.id = this.config.id;
 	    this.element = div;
	},
	render: function(obj) {
		if(!obj) {
			obj = document.body;
		}
		obj.appendChild(this.element);
	},
	getElement: function() {
		return this.element;
	},
	display: function(type) {
		this.element.style.display = type;
	},
	destroy: function() {
		document.body.removeChild(this.element);
	},
	changeColor: function(color) {
		this.element.style.background = color;
	},
	getState: function() {
		return this.state;
	},
	setState: function(state) {
		this.state = state;
	},
	innerHTML: function(html) {
		this.element.innerHTML = html;
	},
	onclick: function() {
		var element = this.element;
		this.element.onclick = function() {
			var inputDiv = document.inputDiv;
			if(!inputDiv) {
				var input = document.createElement("input");
				input.type = "text";
				input.maxLength = 10;
				input.style.height = "18px";
				
				var commit = document.createElement("input");
				commit.type = "button";
				commit.value = "确定";
				
				inputDiv = document.createElement("div");
				inputDiv.style.position = "absolute";
				inputDiv.style.zIndex = Terren.Config.zIndex + 2;
				inputDiv.appendChild(input);
				inputDiv.appendChild(commit);
				inputDiv.input = input;
				inputDiv.commit = commit;
				document.body.appendChild(inputDiv);
				document.inputDiv = inputDiv;
			}
			inputDiv.style.top = element.style.top;
			inputDiv.style.left = element.style.left;
			
			inputDiv.commit.onclick = function() {
				var innerhtml = element.innerHTML;
				if(innerhtml != inputDiv.input.value) {
					element.innerHTML = inputDiv.input.value;
					element.style.color = "#ff4200";
					element.cacheobject.name = inputDiv.input.value;
				}
				inputDiv.style.display = "none";
			}
			
			var value =  element.innerHTML;
			inputDiv.input.value = value;
			inputDiv.input.size = value.length == 0 ? 10 : value.length * 2;
			inputDiv.style.display = "";
		}
	}
}

/**
 * 按钮
 * @param {} config
 */
Terren.element.Button = function(config) {
	this.config = { // 面板参数
		id: 'terren',
		type: 'button',
		value: '按钮',
		style: {marginTop:5 + "px",marginLeft:15 + "px"}
	}
	this.initConfig(config); // 初始化按钮参数
	this.element; // 按钮元素
	this.init(); // 初始化按钮
}
Terren.element.Button.prototype = {
	initConfig: function(config) {
		for(var i in config) { // 自定义参数赋值
			eval("this.config." + i + "=config." + i);
		}	
	},
	init: function() {
		var button = document.createElement("input");
    	for(var i in this.config) {
    		if(i != "style") {
    			button.setAttribute(i, this.config[i]);
    		} else {
    			for(var j in this.config.style) {
    				// button.style.setAttribute(j, this.config.style[j]);
    				eval("button.style." + j + "='" + this.config.style[j] + "'");
    			}
    		}
		}
		button.id = this.config.id;
 	    this.element = button;
	},
	render: function(obj) {
		if(!obj) {
			obj = document.body;
		}
		obj.appendChild(this.element);
	},
	getElement: function() {
		return this.element;
	},
	display: function(type) {
		this.element.style.display = type;
	},
	destroy: function() {
		document.body.removeChild(this.element);
	}
}

/**
 * 树面板
 * @param {} config
 */
Terren.element.TreePanel = function(config) {
	this.config = { // 树参数
		top:  0 + "px",
		id: 'terren',
		left: window.top != window ? 1024 / 2 - 800 / 2 + "px" : window.screen.width / 2 - 800 / 2 + "px",
		width: 800 + "px",
		height: 200 + "px",
		position: "absolute",
		textAlign: 'left',
	    zIndex: Terren.Config.zIndex + 2,
	    border: '1px solid #FF7400',
	    filter: 'alpha(opacity=95)',
	    opacity: 0.95,
	    padding: "2 0",
	    background: Terren.Config.color.white,
	    fontFamily: '宋体',
	    fontSize: '14px',
	    overflow: 'auto'
	}
	this.element; // 树元素
	this.root; // 主节点元素
	this.commit; // 提交
	this.reset; // 重置
	this.initConfig(config); // 初始化树参数
	this.init(); // 初始化树
}
Terren.element.TreePanel.prototype = {
	initConfig: function(config) {
		for(var i in config) { // 自定义参数赋值
			eval("this.config." + i + "=config." + i);
		}
	},
    init: function() {
    	var htmls = document.getElementsByTagName("html");
    	if(htmls.length > 0) {
    		this.root = new Terren.element.TreeNode(htmls[0]);
    	}
    	var div = document.createElement("div");
    	for(var i in this.config) {
    		// div.style.setAttribute(i,this.config[i]);
    		eval("div.style." + i + "='" + this.config[i] + "'");
		}
		div.id = this.config.id;
		var ul = document.createElement("ul");
		div.appendChild(ul);
		
 	    this.element = div;
 	    if(this.root) {
 	    	this.root.render(ul);
 	    }
 	    this.renderButton();
 	    this.scroll();
    },
    render: function(obj) {
    	if(!obj) {
			obj = document.body;
		}
		obj.appendChild(this.element);
    },
    getElement: function() {
		return this.element;
	},
	scroll: function() {
		var element = this;
		var win = window.top != window ? window.top : window;
		win.onscroll = function () {
	 		var scrollTop = win.pageYOffset || win.document.documentElement.scrollTop || win.document.body.scrollTop  || 0;
		    element.element.style.top = scrollTop + "px";
		}
	},
	getCommit: function() {
		var element = this;
		this.commit = new Terren.element.Button({value:'提交'});
		this.commit.element.onclick = function () {
			var list = Terren.Config.selectList;
			var block_querys = "";
			for(var i=0;i<list.length;i++) {
				var object = list[i];
				var block_query = Terren.util.getBlockQuery(object);
				if(object.name) {
					block_query += Terren.Config.separator + encodeURIComponent(object.name);
				}
				block_querys += block_query;
				if(i < list.length - 1) {
					block_querys += Terren.Config.split;
				}
			}
			
			var config = {
				url: Terren.path,
				params: "updateBlock?callback=json&block_querys=" + block_querys + Terren.util.cache.params,
				callBack: element.script_proxy,
				element: element
			}
			new Terren.element.script_proxy(config);
		}
		return this.commit;
	},
	getReset: function() {
		var element = this;
		this.reset = new Terren.element.Button({value:'重置'});
		this.reset.element.onclick = function () {
			element.runReset();
		}
		return this.reset;
	},
	runReset: function() {
		Terren.util.clearSelectList(); // 清空选择的数组
		var config = new Terren.element.config({type: 2});
		config.script_ajax(Terren.util.cache.params);
	},
	renderButton: function() {
		this.getCommit().render(this.element);
		this.getReset().render(this.element);
	},
	script_proxy: function(element) {
		this.element.script_callback(element);
	},
	script_callback: function(element) {
		if(json.success) {
			alert("提交成功！");
			element.runReset();
		}
	}
}

/**
 * 树叶
 * @param {} config
 */
Terren.element.TreeNode = function(config) {
	var index = Terren.util.cache.idIndex++;
	this.config = { // 叶子参数
		id:  "tree_node_" + index,
		color: "#333333",
		fontFamily: "微软雅黑",
		listStyleType: "none",
		margin: "0px 18px",
		attrType: ["id","className","src","href"]
	}
	this.cacheNode;
	this.attributes = ""; // 元素参数
	this.num = 0; // 不符合要求的元素个数
	this.element; // 叶子元素
	this.initConfig(config); // 初始化参数
	this.init(); // 初始化
}
Terren.element.TreeNode.prototype = {
	initConfig: function(config) {
		for(var i=0;i<this.config.attrType.length;i++) {
			var param = this.config.attrType[i];
			var attr = config.getAttribute(param); // ie
			if(param == "className") {
				param = "class";
				if(!attr && attr == null) {
					attr = config.getAttribute(param); // w3c
				}
			}
			if(attr && attr != null) {
				this.attributes += " " + param + "=" + attr;
			}
		}
		this.cacheNode = config;
	},
	getDiv: function() {
		var div = document.createElement("div");
    	div.id = this.config.id;
    	div.style.cursor = "pointer";
    	
    	var add = "<span></span>";
    	var object = this.cacheNode;
    	if(object) {
    		var childNodes = object.childNodes;
    		var num = 0;
    		for(var i=0;i<childNodes.length;i++) {
				var node = childNodes[i];
				if(!node.nodeType || node.nodeType != 1 || node.id == 'terren') {
					num++;
				}
			}
			if(childNodes.length - num > 0) {
				add = "<span>+</span>";
			}
    	}
    	
    	div.innerHTML = add + " <span>&lt;" + this.cacheNode.nodeName + this.attributes + "&gt;</span>";
    	return div;
	},
    init: function() {
    	var li = document.createElement("li");
    	for(var i in this.config) {
    		// li.style.setAttribute(i,this.config[i]);
    		eval("li.style." + i + "='" + this.config[i] + "'");
    	}
    	var div = this.getDiv();
    	li.appendChild(div);
    	var ul = document.createElement("ul");
    	li.appendChild(ul);
    	this.element = li;
    	this.ondisplayclick();
    	this.onclick();
    	this.onmouseover();
    	this.onmouseout();
    },
    ondisplayclick: function() {
    	var element = this;
    	this.element.firstChild.firstChild.onclick = function () {
	    	var object = element.cacheNode;
	    	if(!object) {
    			return ;
    		}
    		var ul = this.parentNode.nextSibling;
    		var li = this.parentNode.parentNode;
			var childNodes = object.childNodes;
			for(var i=0;i<childNodes.length;i++) {
				var node = childNodes[i];
				if(!node.nodeType || node.nodeType != 1 || node.id == 'terren') {
					element.num++;
					continue;
				}
				if(ul.childNodes.length + element.num < childNodes.length) {
					var treeNode = new Terren.element.TreeNode(node);
					treeNode.render(ul);
				} else {
					if(ul.style.display == "none") {
						ul.style.display = "";
						this.innerHTML = "-";
					} else {
						ul.style.display = "none";
						this.innerHTML = "+";
					}
					break;
				}
				this.innerHTML = "-";
				
			}
    	}
    },
    onclick: function() {
    	var element = this;
    	this.element.firstChild.lastChild.onclick = function() {
    		var object = element.cacheNode;
	    	if(!object) {
    			return ;
    		}
    		
    		var _boder = object.style.border;
    		var _color = object.style.color;
    		object.style.border = "1px solid #356AA0";
    		object.style.color = "#CC0000";
    		var jsoup = Terren.util.getElementPath(object);
    		alert(jsoup);
    		object.style.border = _boder;
    		object.style.color = _color;
    		
    		var _html = this.innerHTML;
    		if(_html.indexOf("[") == -1) {
    			this.innerHTML = this.innerHTML + " - {<font color=red>" + jsoup + "</font>}";
    		}
    		Terren.util.removeChild(element.cacheNode);
    		
    		return ;
    		var config = Terren.util.getElementParams(object);
    		var panel = this.parentNode.panel;
    		if(panel) {
    			if(!Terren.util.getBlockQuery(object)) { // 没有id和class的节点
    				return ;
    			}
    			if(panel.getState() == 1) { // 未选择
    				panel.changeColor(Terren.Config.color.orange);
    				panel.setState(3);
    				object.name = object.block.name;
    				Terren.Config.selectList.push(object);
    			} else { // 已选择 新选择
    				panel.changeColor(Terren.Config.color.black);
    				panel.setState(1);
    				object.panel_filter.display("none"); // 隐藏滤镜图层
    				Terren.util.removeList(Terren.Config.selectList,object);
    			}
    		}
    	}
    },
    onmouseover: function() {
    	var element = this;
    	this.element.firstChild.onmouseover = function() {
    		var object = element.cacheNode;
    		if(!object) {
    			return ;
    		}
    		if(object.panel) {
    			this.panel = object.panel;
    		}
    		if(!Terren.util.getBlockQuery(object)) { // 没有id和class的节点
				// return ;
			}
    		if(this.panel) {
    			this.panel.display("");
    			if(this.panel.getState() == 2 || this.panel.getState() == 3) { // 已选择 新选择
    				this.panel.changeColor(Terren.Config.color.red);
    			}
    		} else {
    			this.panel = Terren.util.createPanel(object,Terren.Config.color.black,1);
	    		object.panel = this.panel;
	    		
	    		var block = {name: '区块信息'};
	    		object.block = block
	    		object.blocktype = 2;
	    		
	    		this.panel_filter =  Terren.util.createFilterPanel(object);
	    		this.panel_filter.display("none");
	    		object.panel_filter = this.panel_filter;
    		}
    	}
    },
    onmouseout: function() {
    	var element = this;
    	this.element.firstChild.onmouseout = function() {
    		var object = element.cacheNode;
    		if(object.panel) {
    			this.panel = object.panel;
    		}
    		if(this.panel) {
    			if(this.panel.getState() == 1) { // 未选择
    				this.panel.display("none");
    			} else if (this.panel.getState() == 2){ // 已选择
    				this.panel.changeColor(Terren.Config.color.blue);
    			} else { // 新选择
    				this.panel.changeColor(Terren.Config.color.orange);
    			}
    		}
    	}
    },
    render: function(obj) {
		obj.appendChild(this.element);
    },
    getElement: function() {
		return this.element;
	}
}

// 跨域代理
Terren.element.script_proxy = function(config) {
	this.config = config;
	this.init();
}
Terren.element.script_proxy.prototype = {
	init: function() {
		var random = Math.floor(Math.random() * 100000);
    	var url = this.config.url + this.config.params + "&random=" + random;
	 	var _script = document.createElement("script");
	 	_script.setAttribute("type", "text/javascript");
	 	_script.setAttribute("src", url);
	    document.getElementsByTagName("head")[0].appendChild(_script);
	    _script.config = this.config;

	    _script.onload = _script.onreadystatechange = function(){
			var state = this.readyState;
	        if (!state || state == "loaded" || state == "interactive" || state == "complete") {
	            this.config.callBack(this.config.element);
	        }     
	    }
	}
}

Terren.util = {
	cache: {
		href: window.location.href,
		idIndex: 0,
		params: ''
	},
	elementTop: function (element){ // 元素X轴位置
		var offset = element.offsetTop;
		if(element.parentIframe) {
			offset += this.elementTop(element.parentIframe);
		}
		if(element.offsetParent != null) {
			offset	+= this.elementTop(element.offsetParent);
		}
		return offset;
	},
	elementLeft: function (element){ // 元素Y轴位置
		var offset = element.offsetLeft;
		if(element.parentIframe) {
			offset += this.elementLeft(element.parentIframe);
		}
		if(element.offsetParent!=null) {
			offset += this.elementLeft(element.offsetParent);
		}
		return offset;
	},
	getElementParams: function(element) { // 得到元素的参数
		var elements = document.getElementsByTagName(element.nodeName);
		for(var i=0;i<elements.length;i++) {
			if(elements[i] == element) {
				var obj = {name: element.nodeName,index: i,id: element.id,cls: element.className};
				return obj;
			}
		}
	},
	getPanelConfig: function(element) { // 获得元素的大小和位置
		var top = Terren.util.elementTop(element) + "px";
		var left = Terren.util.elementLeft(element) + "px";
		var width = element.scrollWidth + "px";
		var height = element.scrollHeight + "px";
		
		var config = {transparence:true,top:top,left:left,width:width,height:height,zIndex:Terren.Config.zIndex};
		return config;
	},
	getElementByAttribute: function (object) { // 通过属性获得元素
		var nodes = document.getElementsByTagName(object.nodeName);
		for(var i=0;i<nodes.length;i++) {
			var node = nodes[i];
			var attribute = object.attribute == "class" ? "className" : object.attribute;
			if(node[attribute] == object.value) {
				return node;
			}
		}
	},
	clearSelectList: function () { // 清空选择的数组 （重置功能）
		var list = Terren.Config.selectList;
		if(list == null || list.length < 1) {
			return ;
		}
		for(var i=0;i<list.length;i++) {
			var object = list[i];
			if(object) {
				if(object.panel) {
					object.panel.destroy();
				}
				if(object.panel_filter) {
					object.panel_filter.destroy();
				}
			}
		}
		Terren.Config.selectList = [];
	},
	getElementChildIndex: function(object,child) {
		var childs = object.getElementsByTagName(child.nodeName);
		if(childs.length <= 1) {
			return null;
		}
		var index = 0;
		for(var i=0;i<childs.length;i++) {
			if(childs[i].nodeName == child.nodeName && childs[i] == child) {
				index = i;
			}
		}
		return index;
	},
	getElementPath: function(object, child) {
		var nodeName = object.nodeName;
		var attribute;
		var value;
		if(object.id != null && object.id != '') {
			attribute = "id";	
			value = object.id;
		} else if(object.className != null && object.className != '')  {
			var x = document.getElementsByClassName(object.className);
			var xlength = x.length;
			if(xlength == 1) {
				attribute = "class";	
				value = object.className;
			}
		}
		if(child != null) {
			var index = Terren.util.getElementChildIndex(object, child);
			child.index = index;
			object.child = child;
		}
		
		if(!attribute || !value) {
			if(nodeName.toLowerCase() == 'body') {
				return Terren.util.getAllPath(object);
			}
			return Terren.util.getElementPath(object.parentNode, object);
		} else {
			var block_query = nodeName + "[" + attribute + "=" + value + "]";
			var pathx = object.child ? " " + Terren.util.getAllPath(object.child) : "";
			var path = block_query + pathx;
			return path.toLowerCase();
		}
	},
	getAllPath: function(object) {
		if(!object.child) {
			var path = object.nodeName;
			if(object.index != null) {
				path += ":eq(" + object.index + ")";
			}
			return path.toLowerCase();
		} else {
			var index = object.index != null ?  ":eq(" + object.index + ") " : " ";
			path = object.nodeName + index + Terren.util.getAllPath(object.child);
			return path.toLowerCase();
		}
	},
	removeChild: function(object) {
		if(object.parentNode && object.nodeName.toLowerCase() != 'body') {
			object.child = null;
			Terren.util.removeChild(object.parentNode);
		}
	},
	getBlockQuery: function(object) { // 获得元素的表达式（div[id=query]）
		var nodeName = object.nodeName;
		var attribute;
		var value;
		if(object.id != null && object.id != '') {
			attribute = "id";	
			value = object.id;
		} else if(object.className != null && object.className != '')  {
			attribute = "class";	
			value = object.className;
		}
		if(!attribute || !value) {
			return ;
		}
		var block_query = nodeName + "[" + attribute + "=" + value + "]";
		return block_query.toLowerCase();
	},
	removeList: function(list,object) { // 将选择的对象从数组删除
		if(list == null || list.length < 1) {
			return ;
		}
		for(var i=0;i<list.length;i++) {
			var object2 = list[i];
			if(object2 == object) {
				list.splice(i,1);
			}
		}
	},
	createPanel: function(object,color,state) { // 创建背景面板
		if(!color) {
			if(object.blocktype == 2) {
				color = Terren.Config.color.blue;
			} else {
				color = Terren.util.getRenderColor(object.block.pv,object.block.totalpv);
			}
		}
		if(!state) {
			state = 2;
		}
		var config = Terren.util.getPanelConfig(object);
		var panel = new Terren.element.Panel(config);
		panel.render();
		panel.changeColor(color);
		panel.setState(state);
		return panel;
	},
	createFilterPanel: function(object) { // 创建滤镜面板
		var text = object.block.pv + "";
		var num = 5;
		if(object.blocktype == 2) {
			text = object.block.name;
			num = 10;
		}
		var config_filter = {
	    	zIndex: Terren.Config.zIndex + 1,
	    	padding: "2px 20px",
	    	fontSize: "18px",
	    	color: Terren.Config.color.red,
	    	background: Terren.Config.color.white,
	    	fontWeight: "bolder",
	 		top: parseInt(object.panel.getElement().style.top.replace("px","")) + parseInt(object.panel.getElement().style.height.replace("px","") / 2) - 20 + "px",
	 		left: parseInt(object.panel.getElement().style.left.replace("px","")) + parseInt(object.panel.getElement().style.width.replace("px","") / 2) - 20 - text.length * num + "px",
	 		filter: 'Alpha(Opacity=100,FinishOpacity=0,Style=2)',
	 		borderRadius: "50px",
	 		opacity: 0.8
	    }
	    var panel_filter = new Terren.element.Panel(config_filter);
 	    panel_filter.innerHTML(text);
 	    panel_filter.render();
 	    if(object.blocktype == 2) {
 	    	panel_filter.getElement().cacheobject = object;
 	    	panel_filter.onclick();
 	    }
 	    
 	    return panel_filter;
	},
	ondisplay: function() { // 自定义监听器 - 监听display状态
		var list = Terren.Config.selectList;
		for(var i=0;i<list.length;i++) {
			var object = list[i];
			if(object) {
				var display = object.style.display;
				if(object.panel) {
					object.panel.display(display);
					object.panel_filter.display(display);
				} else {
					if(display != "none") {
						var panel = Terren.util.createPanel(object);
			    		object.panel = panel;
			    		object.panel.display(display);
			    		
			    		var panel_filter =  Terren.util.createFilterPanel(object);
	    				object.panel_filter = panel_filter;
	    				object.panel_filter.display(display);
					}
				}
			}
		}
		window.setTimeout(Terren.util.ondisplay,100);
	},
	getRenderColor: function(pv,totalpv) {
		var num = 0;
		if(pv != 0 && totalpv != 0) {
			num = pv / totalpv;
		}
		function getColor(num) {
			if(num >= 10) {
				return Terren.Config.render.color1;
			} else if (num >= 8) {
				return Terren.Config.render.color2;
			} else if (num >= 6) {
				return Terren.Config.render.color3;
			} else if (num >= 4) {
				return Terren.Config.render.color4;
			} else if (num >= 2) {
				return Terren.Config.render.color5;
			} else if (num >= 1) {
				return Terren.Config.render.color6;
			} else {
				return Terren.Config.render.color7;
			}
		}
		return getColor(num * 100);
	}
}

// 热图分析
function headmapRun(params) {
	frameTop();
	Terren.util.clearSelectList(); // 清空选择的数组
	var config = new Terren.element.config();
	if(params == undefined) {
		params = "";
	}
 	config.script_ajax2(params);
}
// 热图分析管理
function managerRun(params) {
	frameTop();
	var config = new Terren.element.config({type: 2});
	if(params == undefined) {
		params = "";
	}
	Terren.util.cache.params = params;
 	config.script_ajax(params);
 	callTree();
}
// 树加载
function callTree() {
	var treePanel = new Terren.element.TreePanel();
	treePanel.render();
}
window.onload = function () {
	callTree();
}

